// ========== Copyright Header Begin ==========================================
// 
// OpenSPARC T1 Processor File: Ni_SystemBase.cc
// Copyright (c) 2006 Sun Microsystems, Inc.  All Rights Reserved.
// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
// 
// The above named program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public
// License version 2 as published by the Free Software Foundation.
// 
// The above named program is distributed in the hope that it will be 
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
// 
// You should have received a copy of the GNU General Public
// License along with this work; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
// 
// ========== Copyright Header End ============================================
/************************************************************************
**  
**  Copyright (C) 2002, Sun Microsystems, Inc.
**
**  Sun considers its source code as an unpublished, proprietary
**  trade secret and it is available only under strict license provisions.
**  This copyright notice is placed here only to protect Sun in the event 
**  the source is deemed a published work. Disassembly, decompilation,
**  or other means of reducing the object code to human readable form
**  is prohibited by the license agreement under which this code is
**  provided to the user or company in possession of this copy."
**
*************************************************************************/
#include "Ni/Ni_SystemBase.h"
#include "Memory/GenericMemAdapter.h"
#include "StdMacros.h"
#include "Util/Counter.h"
#include <sstream>
#include <fstream>

using namespace std;
using namespace Riesling;

Ni_SystemBase::Ni_SystemBase()
 : 
    reg_( "system" ),
    cpu0_(*this,0,1)
{
    cpu0_.setAddrSpace( &addressSpace_ );
    reg_.addInstance( "cpu0", SimRegistry::CPU, &cpu0_ );
    reg_.addInstance( "address space", SimRegistry::ADDRESS_SPACE, &addressSpace_ );
    cpu0_.setParentRegistry( &reg_ );
}

Ni_SystemBase::~Ni_SystemBase()
{}

string
Ni_SystemBase::toString() const
{
    ostringstream os;

    os << cpu0_.toString();

    return os.str();
}

void
Ni_SystemBase::step()
{
    Counter::getInstance( "sys_step" )->increment();
    cpu0_.step();
}

Cpu*
Ni_SystemBase::getCpuPtr( uint_t nCpu )
{
    if( nCpu > 0 ){
	RIESLING_THROW_OUT_OF_RANGE( "nCpu is out of range" );
    }

    return &cpu0_;
}

uint_t
Ni_SystemBase::getNCpus() const
{
    return 1;
}


void
Ni_SystemBase::snapshot( SS_SnapShot &ss, const char* prefix )
{
    char extended_prefix[SS_SnapShot::LINE_SIZE];

    // Data members
    sprintf(extended_prefix,"%s.cpu0",prefix);	cpu0_.snapshot(ss, extended_prefix);
}

